#!/bin/bash

harbor_host="registry.cn-beijing.aliyuncs.com"
harbor_namespace="wxw-plus/w1106"
harbor_admin=`echo d3h3XzA1MDZAMTYzLmNvbQo=| base64 -d`
harbor_admin_password=`echo d2FuZzA1MDYK| base64 -d`
echo $harbor_admin_password |  docker login $harbor_host -u $harbor_admin --password-stdin 
set -ex
 docker stop $( docker ps -a -q)  ||true
 docker rmi  $( docker images --filter dangling=true -q --no-trunc) -f ||true

 docker images |grep none | awk '{print $3}'| xargs  docker rmi ||true
for image in ` docker images  --format "{{.Repository}}:{{.Tag}}"  | grep $harbor_host/$harbor_namespace`
do 
  echo ${image}  
   docker rmi  $image -f
done

for image in ` docker images  --format "{{.Repository}}:{{.Tag}}"  `
do 
  echo ${image}  
   docker tag  $image $harbor_host/$harbor_namespace:`docker images --format "{{.Repository}}" $image` ||true
done




for i in ` docker images --format "{{.Repository}}:{{.Tag}}"| grep $harbor_host/$harbor_namespace  `
do
   docker push ${i}  ||true
   docker rmi ${i} -f ||true
done   


 docker system prune --all   --volumes -f